#include "http.hpp"



void testReadFile(){
    std::string buf;
    http_util::Util::ReadFile("./http.hpp", &buf);
    std::cout << buf;
}
void testWriteFile(){
    std::string buf;
    http_util::Util::ReadFile("./http.hpp", &buf);
    http_util::Util::WriteFile("./Readhttp.hppThenWriteCopy.c", buf);

}

void testIsAlphaNum1(){
    for(int i = 1; i < 256; ++i){
        // std::cout << i << ":" << (char)i << ":" << std::isalnum((char)i) << "\n";
        std::cout << i << ":" << (unsigned char)i << ":" << std::isalnum((char)i) << "\n";
    }
}
void testIsAlphaNum(){
    for(int i = 1; i < 256; ++i){
        unsigned char ch = static_cast<unsigned char>(i);
        std::cout << i << ":" << char(i) << ":" << std::isalnum(ch) << "\n";
    }
}
void testUrlEncode(){
    std::string str1 = http_util::Util::UrlEncode("Hello/worl  d/C++", false);
    std::cout << str1 << "\n";
    std::string str2 = http_util::Util::UrlEncode("Hello/worl  d/C++", true);
    std::cout << str2 << "\n";

}
void testUrlDecode(){
    std::string str = http_util::Util::UrlEncode("Hello/worl  d/C++", true);
    std::cout << str << "\n";
    std::string str2 = http_util::Util::UrlDecode(str, true);
    std::cout << str2 << "\n";
}

void testValidPath(){
    std::cout << http_util::Util::ValidPath("../hello") << "\n";
    std::cout << http_util::Util::ValidPath("hello/../hello") << "\n";
    std::cout << http_util::Util::ValidPath("imple/../../hello") << "\n";
    std::cout << http_util::Util::ValidPath("../../hello") << "\n";
}

int main(){
    // testReadFile();
    // testWriteFile();
    // testIsAlphaNum();
    // testUrlEncode();
    // testUrlDecode();
    testValidPath();
    return 0;
}


void testSplit(){
    std::string src = ",,,aaa,b,,b,,,,,b,ccc,,,";
    std::vector<std::string> out;
    http_util::Util::Split(src, ",", &out);
    for(auto &str:out){
        std::cout << "[" << str << "]\n";
    }
}

